package com.ruoyi.park23.service.Impl;
import com.ruoyi.CheryEcos.service.impl.EcosServiceImpl;
import com.ruoyi.common.exception.ServiceException;
import com.ruoyi.common.utils.StringUtils;
import com.ruoyi.park23.domain.Ehy1;
import com.ruoyi.park23.mapper.Ehy1Mapper;
import com.ruoyi.park23.service.IEhy1Service;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import javax.validation.Validator;
import java.util.List;

@Service
public class Ehy1ServiceImpl implements IEhy1Service {

    private static final Logger log = LoggerFactory.getLogger(EcosServiceImpl.class);

    @Autowired
    private Ehy1Mapper ehy1Mapper;
    @Autowired
    protected Validator validator;
    @Override
    public List<Ehy1> selectEhy1List(Ehy1 Ehy1) {
        return ehy1Mapper.selectEhy1List(Ehy1);
    }
    @Override public Ehy1 selectEhy1ById(Long id) {
     return ehy1Mapper.selectEhy1ById(id);
   }
   @Override
   public int insertEhy1(Ehy1 Ehy1) {
     return ehy1Mapper.insertEhy1(Ehy1);
   }
   @Override
   public int updateEhy1(Ehy1 Ehy1) {
     return ehy1Mapper.updateEhy1(Ehy1);
   }
   @Override
   public int deleteEhy1ById(Long id) {
     return ehy1Mapper.deleteEhy1ById(id);
   }

   @Override
   public int deleteEhy1ByIds(Long[] ids) {
     return ehy1Mapper.deleteEhy1ByIds(ids);
   }
   @Override
   public List<Ehy1> selectEhy1ByIds(Long[] ids) {
     return ehy1Mapper.selectEhy1ByIds(ids);
   }
   @Override
   public String importEhy1(List<Ehy1> Ehy1List, Boolean isUpdateSupport) {
     if (StringUtils.isNull(Ehy1List) || Ehy1List.size() == 0) {
       throw new ServiceException("导入数据不能为空！");
     }
     int successNum = 0;
     int failureNum = 0;
     StringBuilder successMsg = new StringBuilder();
     StringBuilder failureMsg = new StringBuilder();
     for (Ehy1 ehy1 : Ehy1List) {
       try {
         ehy1Mapper.insertEhy1(ehy1);
         successNum++;
         successMsg.append("<br/>" + successNum + "、数据 " + " 导入成功");
       } catch (Exception e) {
         failureNum++;
         String msg = "<br/>" + failureNum + "、数据 " + " 导入失败：";
         failureMsg.append(msg + e.getMessage());
         log.error(msg, e);
       }
     }
     if (failureNum > 0) {
       failureMsg.insert(0, "很抱歉，导入失败！共 " + failureNum + " 条数据格式不正确，错误如下：");
       throw new ServiceException(failureMsg.toString());
     } else {
       successMsg.insert(0, "恭喜您，数据已全部导入成功！共 " + successNum + " 条，数据如下：");
     }
     return successMsg.toString();
   }
}
